package m1;

import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

import java.util.Scanner;

public class Producer {
    public static void main(String[] args) throws Exception {
        /*创建生产者对象*/
        DefaultMQProducer producer = new DefaultMQProducer("producer");
        //2.设置nameserver服务地址
        producer.setNamesrvAddr("192.168.64.141:9876");
        //3.启动服务
        producer.start();
        //4.声明消息主题

        //输入并发送消息。创建消息对象
        while (true){
            System.out.println("输入消息：");
            String s = new Scanner(System.in).nextLine();
            //Topic一级消息分类
            //Tag二级消息分类
            Message msg = new Message("Topic","TagA",s.getBytes());
            SendResult send = producer.send(msg);
            System.out.println(send);
        }

    }
}
